package com.monitoring.domain.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "electric_meters")
public class ElectricMeter extends Device {
    private double currentReading;
    private double totalConsumption;
    private double powerFactor;
    private double voltage;
    private double current;
    
    // 电表特有的领域方法
    public void updateReading(double newReading) {
        if (newReading > this.currentReading) {
            double consumption = newReading - this.currentReading;
            this.totalConsumption += consumption;
            this.currentReading = newReading;
        }
    }
    
    public void resetTotalConsumption() {
        this.totalConsumption = 0;
    }
}